package com.itlong.cloud.app.resource;

import com.itlong.cloud.POJO.PO.PropertyParkCouponPO;
import com.itlong.cloud.POJO.VO.app.AppGetCouponListVO;
import com.itlong.cloud.app.service.IAppCouponService;
import com.itlong.cloud.user.app.IAppCouponServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *      优惠券相关暴露接口实现类
 * <desc/>
 *
 * @createDate 2018/11/08
 */
@RestController
public class AppCouponServiceResource implements IAppCouponServiceClient {

    @Autowired
    private IAppCouponService iAppCouponService;

    /**
     * <desc>
     *      获取优惠券列表
     * </desc>
     *
     * @return 优惠券列表
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @Override
    @PostMapping(path = "app/coupon/getCouponList")
    public List<AppGetCouponListVO> getCouponList(@RequestParam("phoneNo") String phoneNo,@RequestParam(value = "projectId",required = false) String projectId,
                                                  @RequestParam(value = "redeemCode",required = false) String redeemCode,
                                                  @RequestParam(value = "type", required = false) String type) throws Exception {
        return iAppCouponService.getCouponList(phoneNo, projectId, redeemCode, type);
    }

    /**
     * <desc>
     *      获取优惠券信息 By 兑换码
     * </desc>
     *
     * @return 优惠券信息
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @Override
    @PostMapping(path = "app/coupon/getCouponByRedeemCode")
    public PropertyParkCouponPO getCouponByRedeemCode(@RequestParam("redeemCode") String redeemCode) throws Exception {
        return iAppCouponService.getCouponByRedeemCode(redeemCode);
    }

    /**
     * <desc>
     *      添加(兑换)优惠券
     * </desc>
     *
     * @return 添加的优惠券
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @Override
    @PostMapping(path = "app/coupon/addCoupons")
    public AppGetCouponListVO addCoupons(@RequestBody PropertyParkCouponPO propertyParkCouponPO) throws Exception {
        return iAppCouponService.addCoupons(propertyParkCouponPO);
    }
}
